#include <bits/stdc++.h>
#define N 1000006
using namespace std;
typedef long long ll;

int n, Q;
char s[N+1];
bool vst[N];

int main ()
{
    freopen("good.in", "r", stdin);
    freopen("good.out", "w", stdout);

    scanf("%d %d", &n, &Q);
    scanf("%s", s+1);

    int ans=0;

    for (int t=1; t<=Q; t++) {
        int l, r; scanf("%d %d", &l, &r);
        int cur=0, res=0;
        for (int i=l; i<=r; i++) {
            if (s[i]=='0') {
                res+=(cur==0);
                if (cur>0) { cur--; }
                else { vst[i]=1; }
            }
            else { cur++; }
        }
        cur=0;
        for (int i=r; i>=l; i--) {
            if (s[i]=='0' && !vst[i]) {
                res+=(cur==0);
                if (cur>0) { cur--; }
            }
            else if (s[i]=='1') { cur++; }
        }
        ans^=res;
        for (int i=l; i<=r; i++) { vst[i]=0; }
    }

    printf("%d\n", ans);

    return 0;
}